/*
 * Configuration.cpp
 *
 *  Created on: Jan 6, 2013
 *      Author: fs
 */

#include "Configuration.h"
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <ctime>
#include <string>
#include <getopt.h>

using namespace std;

Configuration::Configuration()
{
	dtmin = DEFAULT_DT_MIN;
	dtmax = DEFAULT_DT_MAX;

	inputFile = NULL;

	populationCount = DEFAULT_POPULATION_COUNT;
	generationCount = DEFAULT_GEN_COUNT;

	kmin = DEFAULT_K_MIN;
	kmax = DEFAULT_K_MAX;

	p = -1;
	c = -1;
}

Configuration::~Configuration()
{
}

void Configuration::parseArgs(int argc, char* argv[])
{
	char c;
		while ((c = getopt(argc, argv, "i:t:p:c:k:K:d:D:P:G:")) != -1)
			switch (c)
			{
			case 'i':
				inputFile = optarg;
				break;
			case 'p':
				p = atof(optarg);
				break;
			case 'c':
				c = atof(optarg);
				break;
			case 'k':
				kmin = atof(optarg);
				break;
			case 'K':
				kmax =atof(optarg);
				break;
			case 'd':
				dtmin = atof(optarg);
				break;
			case 'D':
				dtmax = atof(optarg);
				break;
			case 'P':
				populationCount = atoi(optarg);
				break;
			case 'G':
				generationCount = atoi(optarg);
				break;
			case '?':
				if (isprint(optopt))
					cerr << "Unknown option -" << optopt << endl;
				else
					cerr << "Unknown option character \\x" << optopt << endl;
				break;
			default:
				abort();
				break;
			}
}

void Configuration::printUsage()
{
		cout << "Usage: ppr [options]" << endl;
		cout << "Options:" << endl;
		cout << "  -i FILE\tLoad data from FILE." << endl;
		cout << "  -t THRD COUNT\tThread count." << endl;
		cout << "  -p P VALUE\tSet strictly p value." << endl;
		cout << "  -c CVALUE\tSet strictly c value." << endl;
		cout << "  -k K_MIN\tSet k min value (DEFAULT - 0)." << endl;
		cout << "  -K KMAX\tSet k max value. (DEFAULT - 1)" << endl;
		cout << "  -d D_MIN\tSet d min value (DEFAULT - 0)" << endl;
		cout << "  -D D_MAX\tSet d max value (DEFAULT - 0.027777778)." << endl;
		cout << "  -P POP_COUNT\tSet population count (DEFAULT - 100)." << endl;
		cout << "  -G GEN_COUNT\tSet generation count (DEFAULT - 20)" << endl;
}

void Configuration::printUsedParams()
{
		cout << "Loading file..." << inputFile <<  endl;
		cout << "Params:" << endl;
		if(p != -1)
		{
			cout << "p = " << p << endl;
		}
		if(c != -1)
		{
			cout << "c = " << c << endl;
		}
		cout << "k min = " << kmin << endl;
		cout << "k max = " << kmax << endl;
		cout << "dt min = " << dtmin << endl;
		cout << "dt max= " << dtmax << endl;
		cout << "population count = " << populationCount << endl;
		cout << "generation count = " << generationCount << endl;
		cout << "-------------------------------------\n"  << endl;
}





